﻿using DAO.DAOUtils;
using DAO.IAuthorizationDAO;
using DTO.Authorization;
using DTO.DTOUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO.AuthorizationDAO
{
    public class RoleDAO : IRoleDAO
    {
        public bool Insert(DTO.Authorization.RoleDTO role)
        {
            var parameters = GetListParameter(role);
            return SQLUtils.ExcuteNoneQuery("RoleInsert", ref parameters);
        }

        public bool UpdateById(DTO.Authorization.RoleDTO role)
        {
            var parameters = GetListParameter(role);
            return SQLUtils.ExcuteNoneQuery("RoleUpateById", ref parameters);
        }

        public bool UpdateByName(DTO.Authorization.RoleDTO role)
        {
            var parameters = GetListParameter(role);
            return SQLUtils.ExcuteNoneQuery("RoleUpateByName", ref parameters);
        }

        public bool DeleteById(string roleId)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.RoleId, roleId));
            return SQLUtils.ExcuteNoneQuery("RoleDeleteById", ref parameters);
        }

        public bool DeleteByName(string roleName)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.RoleName, roleName));
            return SQLUtils.ExcuteNoneQuery("RoleDeleteByName", ref parameters);
        }


        public System.Data.DataTable GetByName(string roleName)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.RoleName, roleName));
            return SQLUtils.ExcuteQuery("RoleGetByName", ref parameters);
        }

        public System.Data.DataTable GetById(string roleId)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.RoleId, roleId));
            return SQLUtils.ExcuteQuery("RoleGetById", ref parameters);
        }

        public System.Data.DataTable GetAll()
        {
            var parameters = Parameter.CreateList();
            return SQLUtils.ExcuteQuery("RoleGetAll", ref parameters);
        }

        public List<Parameter> GetListParameter(RoleDTO role)
        {
            return Parameter.CreateList(
                    new Parameter(DTOConstant.RoleId, role.Id),
                    new Parameter(DTOConstant.RoleName, role.RoleName),
                    new Parameter(DTOConstant.RoleDes, role.RoleDes)
                );
        }
    }
}
